<template>
    <div>
        <el-card header='请先登录' class='login-card'>
            <el-form @submit.native.prevent='loginDebounce'>
                <el-form-item label='用户名'>
                    <el-input v-model="model.username" />
                </el-form-item>
                <el-form-item label='密码'>
                    <el-input type='password' v-model="model.password"/> 
                </el-form-item>
                <el-form-item  >
                    <el-button type='primary' native-type='submit'>登录</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script>
    import { debounce } from '@/common'
    export default {
        data(){
            return {
                model:{username:'admin',password:'123456'}
            }
        },
        methods:{
            loginDebounce(){
                debounce(async ()=>{
                    const res = await this.$http.post('login',this.model)
                    // console.log(res.data.data.token);
                    sessionStorage.token = res.data.data.token
                    sessionStorage.username = this.model.username
                    this.$message({
                        type:'success',
                        message:'登录成功'
                    })
                    this.$router.push('/')
                },1000)
            }
        }
    }
</script>



<style scoped>
    .login-card{
        width: 25rem;
        margin : 5rem auto ;
    }
</style>